//
//  LSVisitorView.swift
//  新浪微博
//
//  Created by 梁森 on 16/6/25.
//  Copyright © 2016年 梁森. All rights reserved.
//

import UIKit
import SnapKit
class LSVisitorView: UIView {
    var closure:(()->())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        backgroundColor = UIColor(red: 237/255.0, green: 237/255.0, blue: 237/255.0, alpha: 1.0)
        addSubview(feedImageView)
        addSubview(maskImageView)
        addSubview(iconImageView)
        addSubview(messageLabel)
        addSubview(logInBtn)
        addSubview(RegistBtn)
        feedImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        maskImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        iconImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.width.equalTo(224)
            make.height.equalTo(36)
            make.top.equalTo(maskImageView.snp_bottom).offset(16)
            make.centerX.equalTo(maskImageView)
        }
        logInBtn.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 100, height: 36))
            make.leading.equalTo(messageLabel.snp_leading)
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
        }
        RegistBtn.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 100, height: 36))
            make.trailing.equalTo(messageLabel)
            make.top.equalTo(logInBtn)
        }
    }
    
    
    func setUpVisitorInfo(image:String?,title:String?){
        if let img = image,let tit = title{
            feedImageView.image = nil
            iconImageView.image = UIImage(named: img)
            messageLabel.text = tit
        }else{
            setUpAni()
        }
    }
    
    @objc private func btnClick(){
        closure?()
    }
    
    private func setUpAni(){
        let Ani = CABasicAnimation(keyPath: "transform.rotation")
        Ani.duration = 10
        Ani.toValue = M_PI * 2
        Ani.repeatCount = MAXFLOAT
        Ani.removedOnCompletion = false
        feedImageView.layer.addAnimation(Ani, forKey: nil)
    }
    
    private lazy var feedImageView:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    
    private lazy var maskImageView:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    
    private lazy var iconImageView:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    
    private lazy var messageLabel:UILabel = {
        let lab = UILabel()
        lab.textColor = UIColor.orangeColor()
        lab.text = "关注一些人，回这里看看有什么惊喜\n关注一些人，回这里看看有什么惊喜"
        lab.font = UIFont.systemFontOfSize(12)
        lab.numberOfLines = 0
        lab.textAlignment = .Center
        return lab
        }()
    private lazy var logInBtn:UIButton = {
        let btn = UIButton()
        btn.addTarget(self, action: "btnClick", forControlEvents: UIControlEvents.TouchUpInside)
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        btn.setTitle("登陆", forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        return btn
    }()
    private lazy var RegistBtn:UIButton = {
        let btn = UIButton()
        btn.addTarget(self, action: "btnClick", forControlEvents: UIControlEvents.TouchUpInside)
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        btn.setTitle("注册", forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        return btn
    }()
}
